<template>
	<view>
		<u-navbar title="查看明細" placeholder autoBack>
			<view class="flexright" slot="right" @click="messageTime.timeShow=true">
				<u-icon name="calendar" color="#FFB800" size="24"></u-icon>
			</view>
		</u-navbar>
		<u-sticky bgColor="#fafafa">
			<view class="mainpadding flexcenter">
				<view class="hui_text main_size bold" v-show="!start_time || !end_time">點擊右上角進行時間篩選</view>
				<view class="hui_text main_size bold" v-show="start_time && end_time">篩選區間：{{start_time}}至{{end_time}}</view>
			</view>
			
			<u-tabs :list="tabslist" :scrollable="false"  lineColor="#ffb800" @click="changetab"
					:activeStyle="{
			    color: '#ffb800',
			    fontWeight: 'bold',
			    transform: 'scale(1.05)'
			}" :inactiveStyle="{
			            color: '#333333',
						fontWeight: '540',
			            transform: 'scale(1)'
			        }" itemStyle="padding-left: 10px; padding-right: 10px; height: 44px;"></u-tabs>
		</u-sticky>
		<view class="mainpadding">
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage" style="margin-top: 100rpx;" ></view>
			</view>
			<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.order_sn">
				<view class="flexbetween">
					<view class="main_size xiaohei">{{item.order_sn}}</view>
					<view class="main_size huang_text">已完成</view>
				</view>
				<view class="margin_top flexbetween">
					<view class="xiaohei">{{http.timereturn(item.createtime*1000)}}</view>
					<view class="xiaohei">點數支付</view>
				</view>
				<view class="bghui flexbetween radius mainpadding_top" v-if="tabsid==1">
					<view class="flexleft">
						<view class="xiaohei">訂單點數:</view>
						<view class="xiaohuang">${{item.countmoney}}</view>
					</view>
					<view class="flexleft">
						<view class="xiaohei">實際撥款:</view>
						<view class="xiaohuang">${{item.paymoney}}</view>
					</view>
				</view>
				<view class="bghui flexbetween radius mainpadding_top" v-if="tabsid==2">
					<view class="flexleft">
						<view class="xiaohei">訂單點數:</view>
						<view class="xiaohuang">${{item.count_money}}</view>
					</view>
					<view class="flexleft">
						<view class="xiaohei">商品總點數:</view>
						<view class="xiaohuang">${{item.goods_money}}</view>
					</view>
				</view>
			</view>
		</view>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tabsid: 1,
				tabslist: [{
						name: '商品訂單',
						value: 1,
					},{
						name: '呼叫訂單',
						value: 2,
					}
				],
				page: 1,
				list: {
					data: []
				},
				start_time: "",
				end_time: "",
				messageTime: {
					mode: "date",
					timeShow: false,
					title: "請選擇開始時間"
				},
				pagedown: false
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			changetab(e) {
				this.tabsid = e.value
				this.init()
			},
			init(isPage, page) {
				let _this = this
				let url = '/api/shop/order_mx'
				uni.showLoading({
					title:"請稍後",
					mask:true,
				})
				let data = {
					page: page || 1,
					starttime: Number(new Date(this.start_time)) / 1000 || "",
					end_time: Number(new Date(this.end_time)) / 1000 || "",
					shop_id: uni.getStorageSync("shop_id"),
					type:this.tabsid
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						uni.hideLoading()
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			timeConfirm(e) {
				console.log(e,"999");
				if(this.messageTime.title == "請選擇開始時間"){
					this.start_time = e
					setTimeout(()=>{
						this.messageTime.title  = "請選擇結束時間"
						this.messageTime.timeShow = true
					},100)
				}else{
					this.messageTime.title = "請選擇開始時間"
					this.end_time = e
					this.init()
				}
				
			},
		}
	}
</script>

<style>

</style>
